﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>合同管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <%--基础CSS类库--%>
    <link href="/script/ext/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
    <link href="/style/css/tool-icon-16.css" rel="stylesheet" type="text/css" />
    <link href="/style/css/loading.css" rel="stylesheet" type="text/css" />
    <%--Jquery插件--%>
    <script src="/script/ext/adapter/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="/script/ext/adapter/jquery/ext-jquery-adapter.js" type="text/javascript"></script>
    <%--Ext类库--%>
    <script src="/script/ext/ext-all.js" type="text/javascript"></script>
    <script src="/script/ext/src/locale/ext-lang-zh_CN.js" type="text/javascript"></script>
    <script src="/script/jQuery/jquery_query-2_1_7.js" type="text/javascript"></script>
    <%--自定义类库--%>
    <script src="/script/Jxym-all-debug.js" type="text/javascript"></script>
    <script src="/script/ext/ux/form/Ext.ux.form.CheckboxGroup.js" type="text/javascript"></script>
    <script src="/script/ext/ux/form/ComboBoxTree.js" type="text/javascript"></script>
    <link href="/script/ext/ux/form/FileUploadField.css" rel="stylesheet" type="text/css" />
    <script src="/script/ext/ux/form/FileUploadField.js" type="text/javascript"></script>
    <script type="text/javascript" src="../FCKeditor/fckeditor.js"></script>
    <script type="text/javascript">
        /************************************************         * Copyright (C) 2011 东北农业大学(NEAU)         * 版权所有。         * 文件名： index.htm         * 版本号：v1.0         * 文件功能描述：调动管理         * 作者：韩慧超         * 创建日期： 2010-04-15         *          * 版本号：         * 修改人：         * 修改日期：         * 修改描述：        ************************************************/
        Ext.BLANK_IMAGE_URL = "/script/ext/resources/images/s.gif";
        Ext.onReady(function () {
            var modelid = jQuery.query.get("modelid");
            /*初始化快速提示*/
            Ext.QuickTips.init();
            /*将提示显示在form属性旁边*/
            Ext.form.Field.prototype.msgTarget = "qtip";

            var ClassComboBoxTree = new Ext.ux.ComboBoxTree({
                fieldLabel: "分类",
                hiddenName: "DepartmentTree",
                name: "DepartmentTree",
                emptyText: "请选择分类",
                editable: false,
                selectNodeModel: 'all',
                anchor: "100%",
                tree: {
                    xtype: 'treepanel',
                    lines: true, rootVisible: false, border: false,
                    loader: new Ext.tree.TreeLoader({ dataUrl: 'Server/ClassList.aspx' }),
                    root: new Ext.tree.AsyncTreeNode({ text: '分类', id: "0", leaf: false })
                }
            });

            var DepmetTreeRoot = new Ext.tree.AsyncTreeNode({ text: '分类树', id: 'DepmetTreeRoot', expanded: true, leaf: false });

            function DepmetAdd(tree, treeRoot, selectNode, isTj) {
                if (selectNode) {
                    parentNode = selectNode.parentNode;
                    Ext.Msg.prompt("添加分类", "请输入分类名称", function (btn, text) {
                        if (btn == "ok") {
                            if (text != "") {
                                Ext.Ajax.request({
                                    url: "server/ClassAdd.aspx",
                                    method: 'POST',
                                    params: { modelid: modelid, ClassID: 0, ModuleName: "workflow_formclass", ClassName: text, ParentID: isTj ? ((parentNode != undefined && parentNode.id != "DepmetTreeRoot") ? parentNode.id : 0) : selectNode.id },
                                    success: function (response) {
                                        var json = Ext.util.JSON.decode(response.responseText);
                                        if (json.success) {
                                            Ext.Msg.alert("提示", json.msg);
                                            tree.loader.load(treeRoot);
                                        } else {
                                            Ext.Msg.alert("错误", json.msg);
                                        }
                                    }
                                });
                            } else {
                                Ext.Msg.alert("提示", "请输入名称");
                            }
                        }
                    });
                }
            }
            var DepmetTree = new Ext.tree.TreePanel({
                loader: new Ext.tree.TreeLoader({ dataUrl: "SERVER/ClassList.aspx?r=" + new Date().getTime() }),
                id: 'DepmetTree',
                region: 'west',
                width: 140,
                minSize: 140,
                margins: '5 0 5 5',
                cmargins: '5',
                bodyStyle: "padding:2px;",
                title: "表单分类",
                split: true,
                rootVisible: false,
                lines: true,
                autoScroll: true,
                animate: true,
                collapsible: true,
                containerScroll: true,
                tbar: [{ iconCls: 'icon-expand-all',
                    tooltip: '全部展开',
                    handler: function () { DepmetTreeRoot.expand(true); }
                }, { iconCls: 'icon-collapse-all',
                    tooltip: '全部折叠',
                    handler: function () { DepmetTreeRoot.collapse(true); }
                }, { iconCls: 'icon-add',
                    tooltip: '添加同级',
                    handler: function () {
                        var selectNode = DepmetTree.getSelectionModel().getSelectedNode();
                        DepmetAdd(DepmetTree, DepmetTreeRoot, selectNode, true);
                    }
                }, { iconCls: 'icon-add',
                    tooltip: '添加子集',
                    handler: function () {
                        var selectNode = DepmetTree.getSelectionModel().getSelectedNode();
                        DepmetAdd(DepmetTree, DepmetTreeRoot, selectNode, false);
                    }
                }, { iconCls: 'icon-edit',
                    tooltip: '编辑',
                    handler: function () {
                        var selectNode = DepmetTree.getSelectionModel().getSelectedNode();
                        if (selectNode) {
                            Ext.Msg.prompt("编辑分类", "请输入分类", function (btn, text) {
                                if (btn == "ok") {
                                    if (text != "") {
                                        Ext.Ajax.request({
                                            url: "SERVER/ClassAdd.aspx",
                                            method: 'POST',
                                            params: { modelid: modelid, ClassName: text, ClassID: selectNode.id, ModuleName: "workflow_formclass" },
                                            success: function (response) {
                                                var json = Ext.util.JSON.decode(response.responseText);
                                                if (json.success) {
                                                    Ext.Msg.alert("提示", json.msg);
                                                    DepmetTree.loader.load(DepmetTreeRoot);
                                                } else {
                                                    Ext.Msg.alert("错误", json.msg);
                                                }
                                            }
                                        });
                                    } else {
                                        Ext.Msg.alert("提示", "请输入名称");
                                    }
                                }
                            }, "", "", selectNode.text);
                        }
                    }
                }, { iconCls: 'icon-del',
                    tooltip: '删除',
                    handler: function () {
                        var selectNode = DepmetTree.getSelectionModel().getSelectedNode();
                        if (selectNode) {
                            Ext.Msg.confirm("确认提示", "确认要删除" + selectNode.text + "?", function (btn) {
                                if (btn == "yes") {
                                    Ext.Ajax.request({
                                        url: "SERVER/ClassDel.aspx",
                                        method: 'POST',
                                        params: { modelid: modelid, ClassID: selectNode.id },
                                        success: function (response) {
                                            var json = Ext.util.JSON.decode(response.responseText);
                                            if (json.success) {
                                                Ext.Msg.alert("提示", json.msg);
                                                DepmetTree.loader.load(DepmetTreeRoot);
                                            } else {
                                                Ext.Msg.alert("错误", json.msg);
                                            }
                                        }
                                    });
                                }
                            }, "", "", selectNode.text);
                        }
                    }
                }]
            });
            DepmetTree.setRootNode(DepmetTreeRoot);
            DepmetTree.on('click', function (node, e) {
                if (node) {
                    groupStore.load({ params: { start: 0, limit: pageSize, depmetId: node.id} });
                }
            });

            /*定义数据模型*/
            var Info = new Ext.data.Record.create([
              { name: 'FormID', type: 'int', mapping: 'FormID' },
              { name: 'FormName', mapping: 'FormName' },
              { name: 'AddDate', type: 'date', mapping: 'AddDate' }
              ]);
            /*创建数据源*/
            var groupStore = new Ext.data.GroupingStore({
                proxy: new Ext.data.HttpProxy({ url: "../../HR/server/JobChange/JobChangeList.aspx" }),
                reader: new Ext.data.JsonReader({ totalProperty: "Count", root: "List" }, Info),
                sortInfo: { field: 'ChangeDate', direction: 'ASC' }
            });

            /*设置每页条数*/
            var pageSize = 30;
            var cookiePageSize = parseInt(Ext.util.Cookies.get("pageSize"));
            if (cookiePageSize) { pageSize = cookiePageSize; }

            /*加载数据源*/
            groupStore.load({ params: { start: 0, limit: pageSize} });

            /*创建选择列模型*/
            var sm = new Ext.grid.CheckboxSelectionModel();

            /*定义列模型*/
            var cm = new Ext.grid.ColumnModel([
                sm,
                { id: 'FormID', header: '编号', dataIndex: 'FormID', width: 50, sortable: true },
                { id: 'FormName', header: '表单名称', dataIndex: 'FormName', width: 150, sortable: true },
                { id: 'AddDate', header: '建立时间', dataIndex: 'AddDate', width: 100, sortable: true, renderer: Ext.util.Format.dateRenderer('Y-m-d') }
            ]);

            /*创建下[每页行数]拉框*/
            var comboBox = new Ext.form.ComboBox({
                width: 50,
                typeAhead: true,
                triggerAction: 'all',
                lazyRender: true,
                mode: 'local',
                title: "每页行数",
                emptyText: pageSize,
                store: new Ext.data.ArrayStore({ id: 0, fields: ['myId', 'displayText'], data: [[10, 10], [20, 20], [30, 30], [50, 50], [100, 100]] }),
                valueField: 'myId',
                displayField: 'displayText'
            });
            comboBox.on("select", function (combo, record, index) {
                Ext.util.Cookies.set("pageSize", record.id);
                window.location.reload();
            });

            /*创建数据窗格*/
            var grid = new Ext.grid.GridPanel({
                region: "center",
                margins: "5 5 0 5",
                border: true,
                store: groupStore,
                autoExpandColumn: "FormName",
                loadMask: { msg: '正在努力的加载，请稍等片刻..' },
                view: new Ext.grid.GroupingView(),
                cm: cm,
                sm: sm,
                tbar: [{
                    iconCls: 'icon-add',
                    text: '添加',
                    value: 0,
                    handler: function (btn) {
                        viewport.items.get(1).expand();
                        form.setTitle("信息添加");
                        form.getForm().reset();
                    }
                }, {
                    ref: '../removeBtn',
                    iconCls: 'icon-del',
                    text: '删除',
                    disabled: true,
                    handler: function () {
                        Ext.MessageBox.confirm("确认提示", "确认要删除所选行数据？", function (btn) {
                            if (btn == "yes") {
                                var s = grid.getSelectionModel().getSelections();
                                var delR = new Array();
                                var delRid = new Array();
                                for (var i = s.length - 1; i >= 0; i--) {
                                    var r = s[i];
                                    if (r.get('ID') != undefined) { delRid.push(r.get('ID')); delR.push(r); }
                                }
                                Ext.Ajax.request({
                                    url: "server/ContractDel.aspx?modelid=" + modelid,
                                    method: 'POST',
                                    params: { id: delRid },
                                    success: function (response) {
                                        var json = Ext.util.JSON.decode(response.responseText);
                                        if (json.success) {
                                            for (var i = 0; i < delR.length; i++) {
                                                if (json.ids.valueOf(delR[i].get('ID'))) { groupStore.remove(delR[i]) }
                                            }
                                            Ext.Msg.alert("提示", "已删除" + json.count + "行<br/>" + json.msg);
                                        } else {
                                            Ext.Msg.alert("错误", json.msg);
                                        }
                                    }
                                });
                            }
                        });
                    }
                }, {
                    ref: '../viewBtn',
                    iconCls: 'icon-view',
                    text: '查看',
                    disabled: true,
                    handler: function () {
                        var s = grid.getSelectionModel().getSelections();
                        window.open('server/notice/noticeDetail.aspx?id2=' + s[0].get("ID"));
                    }
                }],
                bbar: new Ext.PagingToolbar({
                    store: groupStore,
                    pageSize: pageSize,
                    displayInfo: true,
                    prependButtons: true,
                    items: [comboBox],
                    displayMsg: "本页显示第{0}条到第{1}条数据，共{2}条",
                    emptyMsg: "暂无记录"
                })
            });

            var form = new Ext.form.FormPanel({
                region: 'south',
                title: "信息添加",
                margins: "5",
                collapsible: true,
                expanded: false,
                frame: true,
                split: false,
                height: 450,
                labelAlign: "right",
                labelWidth: 70,
                buttonAlign: "center",
                items: [{
                    layout: 'column',
                    items: [{
                        layout: 'form',
                        columnWidth: .7,
                        items: [{ xtype: 'textfield', fieldLabel: '表单名称', hiddenName: 'FormName', name: 'FormName', anchor: '100%'}]
                    }, { layout: 'form', columnWidth: .3, items: [ClassComboBoxTree] }
                ]
                }, {
                    xtype: 'fckeditor',
                    name: 'documentBody',
                    id: 'documentBody',
                    fieldLabel: '表单编辑器',
                    height: 350
                }],
                buttons: [{ text: "确定", handler: function () {
                    if (form.form.isValid()) {
                        var params = { JobChangeID: form.getForm().findField("JobChangeID").getValue(), NewDepartmentID: DepartmentComboBoxTree.getCtValue() };
                        form.getForm().submit({
                            url: "server/JobChangeAdd.aspx?modelid=" + modelid,
                            params: params,
                            reset: true,
                            submitEmptyText: false,
                            waitTitle: "数据提交",
                            waitMsg: "正在向服务器提交数据请稍后...",
                            success: function (f, action) {
                                if (action.result.success) {
                                    Ext.Msg.alert("提示", action.result.msg);
                                    groupStore.load({ params: { start: 0, limit: pageSize, modelid: modelid, time: new Date().getTime()} });

                                } else {
                                    Ext.Msg.alert("提示", action.result.msg);
                                }
                            }, failure: function (f, action) { Ext.Msg.alert("提示", "数据异常"); }
                        });
                    }
                }
                }, {
                    text: "重置", handler: function () { form.getForm().reset(); }
                }]
            });

            /*创建页面布局*/
            var viewport = new Ext.Viewport({
                layout: 'border',
                items: [DepmetTree, grid, form]
            }); /*布局加载*/viewport.doLayout();
            viewport.items.get(2).collapse();

            /*延时加载*/
            setTimeout(function () { Ext.get('loading').remove(); Ext.get('loading-mask').fadeOut({ remove: true }); }, 400);

            /*有选择行启用删除按钮*/
            grid.getSelectionModel().on('selectionchange', function (sm) {
                grid.removeBtn.setDisabled(sm.getCount() < 1);
                grid.viewBtn.setDisabled(sm.getCount() < 1 || sm.getCount() > 1);
            });
        });


        var oFCKeditorOptions = {
            BasePath: '../fckeditor/',
            Config: {
                //BaseHref: window.location,
                SkinPath: '/fckeditor/editor/skins/office2003/',
                ProcessHTMLEntities: true,
                ProcessNumericEntities: false,
                StartupShowBlocks: true,
                ToolbarCanCollapse: false
            },
            ToolbarSet: 'Default'
        };

        Ext.form.FCKeditor = function (config) {
            this.config = config;
            Ext.form.FCKeditor.superclass.constructor.call(this, config);
            this.FCKid = 0;
            this.MyisLoaded = false;
            this.MyValue = '';
        };

        Ext.extend(Ext.form.FCKeditor, Ext.form.TextArea, {
            onRender: function (ct, position) {
                if (!this.el) {
                    this.defaultAutoCreate = {
                        tag: "textarea",
                        style: "width:100px;height:60px;",
                        autocomplete: "off"
                    };
                }
                Ext.form.TextArea.superclass.onRender.call(this, ct, position);
                if (this.grow) {
                    this.textSizeEl = Ext.DomHelper.append(document.body, {
                        tag: "pre", cls: "x-form-grow-sizer"
                    });
                    if (this.preventScrollbars) {
                        this.el.setStyle("overflow", "hidden");
                    }
                    this.el.setHeight(this.growMin);
                }

                loadFCKeditor(this.name, this.config.height);
            } /*,
            setValue : function(value){
		        FCKeditorSetValue(this.name,value);
		        Ext.form.TextArea.superclass.setValue.apply(this,value);
            },	
            getValue : function(){
		        var value = FCKeditorGetValue(this.name);
		        Ext.form.TextArea.superclass.setValue.apply(this,value);
		        return Ext.form.TextArea.superclass.getValue(this);
            }*/
        });
        Ext.reg('fckeditor', Ext.form.FCKeditor);

        function loadFCKeditor(element, height) {
            oFCKeditor = new FCKeditor(element);
            oFCKeditor.BasePath = oFCKeditorOptions.BasePath;
            oFCKeditor.ToolbarSet = oFCKeditorOptions.ToolbarSet;
            //oFCKeditor.Config = oFCKeditorOptions.Config;
            oFCKeditor.Height = height;
            oFCKeditor.Width = "100%"; // height;
            oFCKeditor.ReplaceTextarea();
        } /*
        function FCKeditorSetValue(name,value){
	        var oEditor = FCKeditorAPI.GetInstance(name);
	        if(oEditor!=undefined) oEditor.SetData(value);
        }
        function FCKeditorGetValue(name){
	        var data = '';
	        var oEditor = FCKeditorAPI.GetInstance(name);
            if(oEditor!=undefined) data=oEditor.GetData();
	        return data;
        }*/

        //    Ext.onReady(function () {
        //        var form = new Ext.form.FormPanel({
        //            labelAlign: 'right',
        //            method: 'GET',
        //            height: 700,
        //            width: 900,
        //            buttonAlign: 'center',
        //            //url: 'docInsertUpdate.php',
        //            labelWidth: 80,
        //            frame: true,
        //            defaultType: 'textfield',
        //            items: [{
        //                name: 'alarmCode',
        //                width: 450,
        //                fieldLabel: 'Alarm Code'
        //            }, {
        //                name: 'alarmText',
        //                width: 450,
        //                fieldLabel: 'Alarm Text'
        //            }, {
        //                xtype: 'fckeditor',
        //                name: 'documentBody',
        //                id: 'documentBody',
        //                fieldLabel: 'Document',
        //                height: 400,
        //                width: 200
        //            }
        //		]
        //        });
        //        form.render(document.body);

        //    });
    </script>
</head>
<body>
    <div id="loading-mask">
    </div>
    <div id="loading">
        <div class="loading-indicator">
            正在努力的加载...
        </div>
    </div>
</body>
</html>
